package com.gzxw.mogublog.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gzxw.mogublog.commons.entity.BlogSort;
import com.gzxw.mogublog.utils.R;
import com.gzxw.mogublog.xo.service.BlogSortService;
import com.gzxw.mogublog.xo.vo.BlogSortVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/blogSort")
public class BlogSortController {

    @Autowired
    private BlogSortService blogSortService;


    @PostMapping("/getList")
    public R getList(@RequestBody BlogSortVO blogSortVO) {
        IPage<BlogSort> pageList = blogSortService.getList(blogSortVO);
        HashMap<String, Object> result = new HashMap<>();
        List<BlogSort> records = pageList.getRecords();
        long total = pageList.getTotal();
        long size = pageList.getSize();
        long current = pageList.getCurrent();
        result.put("records", records);
        result.put("total", total);
        result.put("size", size);
        result.put("current", current);
        return R.success("查询成功!", result);
    }

    // 添加分类
    @PostMapping("/add")
    public R add(@RequestBody BlogSortVO blogSortVO) {

        String message = blogSortService.addBlogSort(blogSortVO);

        return R.success("200", message);

    }

    // 编辑博客分类
    @PostMapping("/edit")
    public R edit(@RequestBody BlogSortVO blogSortVO) {

        String message = blogSortService.editBlogSort(blogSortVO);

        return R.success("200", message);

    }

    // 批量删除
    @PostMapping("/deleteBatch")
    public R deleteBatch(@RequestBody List<BlogSortVO> blogSortVOList) {

        String message = blogSortService.deleteBatch(blogSortVOList);

        return R.success("200", message);
    }

    // 顶置分类
    @PostMapping("/stickBlogSort")
    public R stickBlogSort(@RequestBody BlogSortVO blogSortVO) {

        String message = blogSortService.stickBlogSort(blogSortVO);

        return R.success("200", message);
    }


    // 根据点击量排序
    @GetMapping("/blogSortByClickCount")
    public R blogSortByClickCount() {

        String message = blogSortService.blogSortByClickCount();

        return R.success("200", message);
    }

    // 根据引用量排序
    @GetMapping("/blogSortByCite")
    public R blogSortByCite() {

        String message = blogSortService.blogSortByCite();

        return R.success("200", message);
    }
}
